<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>渠道下账配置</title>
    <link rel="shortcut icon" href="favicon.ico">
    <script src="../../res/js/comm.js"></script>
    <link href="../../res../res/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <script src="../../res/js/ajaxUtil.js"></script>
</head>
<body class="gray-bg">

<style>
    .select2-container--open {
        z-index: 10000000000
    }
</style>


<div class="wrapper wrapper-content animated fadeInRight">
        <div class="panel panel-info">
            <div class="panel-heading"><i class="fa fa-info-circle"></i> 渠道下账配置列表</div>
            <div class="panel-body">

            <div class="ibox-query">
                <div class="row">
                    <form id="pstQueryForm" method="post" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">渠道编码</label>
                            <div class="col-sm-2">
                                <input  name="orderChannel" class="form-control" type="text">
                            </div>
                            <label class="col-sm-1 control-label">渠道名称</label>
                            <div class="col-sm-2">
                                <input name="channelName" class="form-control" type="text">
                            </div>

                            <div>
                                <button style="margin-left: 100px;" class="btn btn-info" onclick='$.openx.query()'
                                        type="button"><i class="glyphicon glyphicon-search"></i> 查询
                                </button>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                    </form>
                </div>
            </div>

            <div class="row row-lg">
                <div class="col-sm-12">
                    <div id="pstBar">
                    	<div id="TableToolbar" class="bars pull-left" >
							<button class="btn btn-warning" onclick='$.openx.insert()' type="button"><i class="glyphicon glyphicon-plus"></i> 新增</button>
							<button class="btn btn-primary" onclick='$.openx.update()' type="button"><i class="glyphicon glyphicon-pencil"></i> 修改</button>
						</div>
                    </div>
                    <table id="table">
                        <thead>
                        <tr>

                            <th data-align="center" data-field="_checkbox_status" data-checkbox="true"></th>
                            <th data-align="center" data-formatter="$.openx.generatorId"> 序号 </th>
                            <th data-align="center" data-field="orderChannel">渠道编码</th>
                            <th data-align="center" data-field="channelName">渠道名称</th>
                            <th data-align="center" data-field="billKind" >单据类别代号</th>
                            <th data-align="center" data-field="paymentModeCode" >支付方式编码</th>
                            <th data-align="center" data-field="cashdeskCode">收银台编号</th>
                            <th data-align="center" data-field="orderCodePrefix">订单编号前缀</th>
                            <th data-align="center" data-field="orderFromCode">订单代码</th>
                            <th data-align="center" data-field="remark">备注</th>

                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>


<script type="text/html" id="pstDialog">
    <form class="form-horizontal" id="pstForm">

        <div class="col-md-12" style="width: 800px;margin-top: 20px">
            <div class="form-group" >
                <label class="col-sm-4 control-label"><font color="red" >* </font>渠道编码：</label>
                <div class="col-sm-8">
                    <input name="orderChannel" id="orderChannel"  maxlength="10" class="form-control" placeholder="请输入渠道编码" type="text" title="必填字段" required="true" {{!d.orderChannel ? '':'readonly'}} value="{{!d.orderChannel ? '':d.orderChannel}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label"><font color="red" >* </font>渠道名称：</label>
                <div class="col-sm-8">
                    <input name="channelName" id="channelName"  maxlength="10" class="form-control" placeholder="请输入渠道名称" type="text"  title="必填字段" required="true" value="{{!d.channelName ? '':d.channelName}}">
                </div>
            </div>
           <div class="form-group">
                <label class="col-sm-4 control-label"><font color="red" >* </font>单据类别代号：</label>
                <div class="col-sm-8">
                    <input name="billKind" id="billKind" class="form-control"  maxlength="1" placeholder="请输入单据类别代号" type="text"  title="必填字段" required="true" value="{{!d.billKind ? '':d.billKind}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label"><font color="red" >* </font>支付方式编码：</label>
                <div class="col-sm-8">
                    <input name="paymentModeCode" id="paymentModeCode" class="form-control"  maxlength="5" placeholder="请输入支付方式编码" required="true" type="text" value="{{!d.paymentModeCode ? '':d.paymentModeCode}}">
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-4 control-label"><font color="red" >* </font>收银台编号：</label>
                <div class="col-sm-8">
                    <input name="cashdeskCode" id="cashdeskCode" class="form-control"  maxlength="5" placeholder="请输入收银台编号" type="text" required="true" value="{{!d.cashdeskCode ? '':d.cashdeskCode}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label"><font color="red" >* </font>订单编号前缀：</label>
                <div class="col-sm-8">
                    <input name="orderCodePrefix" id="orderCodePrefix" class="form-control" placeholder="订单编号前缀"  maxlength="10" type="text" required="true" value="{{!d.orderCodePrefix ? '':d.orderCodePrefix}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label"><font color="red" >* </font>订单代码：</label>
                <div class="col-sm-8">
                    <input name="orderFromCode" id="orderFromCode" class="form-control" placeholder="请输入订单代码"  maxlength="5" type="text" required="true" value="{{!d.orderFromCode ? '':d.orderFromCode}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control" placeholder="请输入备注"  maxlength="50" type="text" >{{!d.remark ? '':d.remark}}</textarea>
                </div>
            </div>
        </div>
    </form>
</script>
<script>


    /**查询参数信息*/
    var url = "/openx/posting/pstConfigService/queryPstConfigForPage";
    //对应接口入参
    var param = {};

    var formId = 'pstQueryForm';
    
    (function () {
        /**设置增删改查的工具条*/
        //$.openx.setTableToolBar('pstBar');
        /**进行表格数据初始化*/
        var data = $.openx.getJsonObj(formId);
        param.bean = data;
        $.openx.initTable("table", url, param);
            //小时和分钟的初始值
    })();



    $.openx.insert = function () {
            var createForm = "pstForm";
            var innerHtml = $.openx.innerHtml('pstDialog');
            laytpl(innerHtml).render({}, function (html) {
                $.openx.openLayer(['800', '550'], '新增渠道下账配置', html, false, function () {
                    if ($.openx.validation(createForm)) {
                        //获取表单数据
                        var param = $.openx.getJsonObj(createForm);
						
                        $X("/posting/pstConfigService","queryOrderChannelIsOnly").callx({
                            orderChannel: param.orderChannel,
                            onResult: function (data) {
                                if (!data) {
                                	layer.tips("渠道编码已存在,不能重复添加！", '#orderChannel', { tips: [2, '#78BA32'] });
                                	$("#orderChannel").focus();
                                }else{
   			                        $X("/posting/pstConfigService", "createPstConfig").callx({
   			                            param: param,
   			                            onResult: function (data) {
   			                                if (data) {
   			                                    $.openx.tableRefresh(null, null, true);
   			                                    layer.closeAll();
   			                                    layer.msg("新增成功,配置两小时后生效",{ time: 3000 });
   			                                }
   			                            },
   			                            onError: function (error) {
   			                                var res = JSON.parse(error);
   			                                layer.msg(res.message)
   			                            }
   			                        });
                                }
                            },
                            onError: function (error) {
                                var res = JSON.parse(error);
                                layer.msg(res.message)
                            }
                    	});
                    }
                });
            });
    }

    $.openx.update = function () {
        $.openx.onClickUpdate(function (rows) {
            var updateForm = "pstForm";
            var innerHtml = $.openx.innerHtml('pstDialog');
            laytpl(innerHtml).render(rows[0], function (html) {
                $.openx.openLayer(['800', '550'], '修改渠道下账配置', html, false, function () {
                    if ($.openx.validation(updateForm)) {
                        //获取表单数据
                        var param = $.openx.getJsonObj(updateForm);
                        $X("/posting/pstConfigService", "updatePstConfig").callx({
                            param: param,
                            onResult: function (data) {
                                if (data) {
                                    $.openx.tableRefresh(null, null, true);
                                    layer.closeAll();
                                    layer.msg("修改成功,配置两小时后生效",{ time: 3000 });
                                }
                            },
                            onError: function (error) {
                                var res = JSON.parse(error);
                                layer.msg(res.message)
                            }
                        });
                    }
                });
            });
        });
    }


    $.openx.query = function () {
        var data = $.openx.getJsonObj(formId);
        param.bean = data;
        $.openx.tableRefresh(url, param);
    }

</script>
</html>
